package com.ruoyi.qywx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.qywx.domain.SysQywxChatdata;
import com.ruoyi.qywx.service.ISysQywxChatdataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业微信Controller
 *
 * @author yaolei
 * @date 2024-06-22
 */
@RestController
@RequestMapping("/qywx/chatdata")
public class SysQywxChatdataController extends BaseController
{
    @Autowired
    private ISysQywxChatdataService sysQywxChatdataService;

    /**
     * 查询企业微信列表
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysQywxChatdata sysQywxChatdata)
    {
        startPage();
        SysUser user = SecurityUtils.getLoginUser().getUser();
        sysQywxChatdata.setDecryptChatMsg(user.getRemark());
        List<SysQywxChatdata> list = sysQywxChatdataService.selectSysQywxChatdataList(sysQywxChatdata);
        return getDataTable(list);
    }

    /**
     * 导出企业微信列表
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:export')")
    @Log(title = "企业微信", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysQywxChatdata sysQywxChatdata)
    {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        sysQywxChatdata.setDecryptChatMsg(user.getRemark());
        List<SysQywxChatdata> list = sysQywxChatdataService.selectSysQywxChatdataList(sysQywxChatdata);
        ExcelUtil<SysQywxChatdata> util = new ExcelUtil<SysQywxChatdata>(SysQywxChatdata.class);
        util.exportExcel(response, list, "企业微信数据");
    }

    /**
     * 获取企业微信详细信息
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:query')")
    @GetMapping(value = "/{seq}")
    public AjaxResult getInfo(@PathVariable("seq") Long seq)
    {
        return success(sysQywxChatdataService.selectSysQywxChatdataBySeq(seq));
    }

    /**
     * 新增企业微信
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:add')")
    @Log(title = "企业微信", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysQywxChatdata sysQywxChatdata)
    {
        return toAjax(sysQywxChatdataService.insertSysQywxChatdata(sysQywxChatdata));
    }

    /**
     * 修改企业微信
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:edit')")
    @Log(title = "企业微信", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysQywxChatdata sysQywxChatdata)
    {
        return toAjax(sysQywxChatdataService.updateSysQywxChatdata(sysQywxChatdata));
    }

    /**
     * 删除企业微信
     */
    @PreAuthorize("@ss.hasPermi('qywx:chatdata:remove')")
    @Log(title = "企业微信", businessType = BusinessType.DELETE)
	@DeleteMapping("/{seqs}")
    public AjaxResult remove(@PathVariable Long[] seqs)
    {
        return toAjax(sysQywxChatdataService.deleteSysQywxChatdataBySeqs(seqs));
    }
}
